package com.syqc.maps.utils

import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.Poi
import com.amap.api.navi.AmapNaviPage
import com.amap.api.navi.AmapNaviParams
import com.amap.api.navi.AmapNaviType
import com.amap.api.navi.AmapPageType
import com.syqc.comlib.base.BaseActivity
import com.syqc.comlib.rx.filterFast
import com.syqc.comlib.utils.AppContext
import com.syqc.comlib.utils.NaviUtil
import com.syqc.monitor.databinding.PopupNaviChooseBinding
import com.syqc.utils.Keys

/**
 *@author  hfjs
 *@time   2024/6/28 15:36
 *@desc
 */
class NaviActivity : BaseActivity<PopupNaviChooseBinding>(PopupNaviChooseBinding::inflate) {
    private lateinit var plate: String
    private lateinit var eLat: String
    private lateinit var eLng: String
    private lateinit var bLat: String
    private lateinit var bLng: String

    override fun initView() {
        plate = intent.getStringExtra(Keys.INTENT_PLATE) ?: ""
        eLat = intent.getStringExtra("eLat") ?: "0"
        eLng = intent.getStringExtra("eLng") ?: "0"
        bLat = intent.getStringExtra("bLat") ?: "0"
        bLng = intent.getStringExtra("bLng") ?: "0"
    }

    override fun setListener() {

        binding.tvPopupLocal.setOnClickListener {
//            NaviUtil.startNavi(plate, eLat.toDouble(), eLng.toDouble())
            navi(plate, LatLng(eLat.toDouble(), eLng.toDouble()))
            finish()
        }

        binding.tvPopupBaidu.filterFast {
            NaviUtil.startToBaiduMap(this@NaviActivity, plate, "${bLat},${bLng}")
            finish()

        }
        binding.tvPopupGaode.filterFast {
            NaviUtil.startToGaodeMap(this@NaviActivity, plate, eLat, eLng)
            finish()
        }

        binding.tvPopupCancel.setOnClickListener {
            finish()
        }
    }

    private fun navi(
        endName: String,
        endPoint: LatLng
    ) {
        val params = AmapNaviParams(
            null, null, Poi(endName, endPoint, ""), AmapNaviType.DRIVER, AmapPageType.ROUTE
        )
        params.setUseInnerVoice(true)
        params.setNeedDestroyDriveManagerInstanceWhenNaviExit(true)
        AmapNaviPage.getInstance().showRouteActivity(
            AppContext.getAppContext(), params,
            MapUtil.mNaviInfoCallback
        )
    }
}